<template>
  <div class="visitor-toVisit">
    <div class="search-group">
      <div class="input-wrap">
        <div class="label">企业名称:</div>
        <div class="input-item">
          <j-input :maxLength="30" clearable v-model="queryParam.factoryName" placeholder="请输入企业名称" />
        </div>
      </div>

      <div class="input-wrap">
        <div class="label">企业编码:</div>
        <div class="label" style="min-width: auto">WN-</div>
        <div class="input-item">
          <j-input :maxLength="30" clearable v-model="queryParam.factoryCode" placeholder="请输入企业编码" />
        </div>
        <div class="label" style="min-width: auto">-</div>
        <div class="input-item">
          <a-input :maxLength="30" clearable v-model="queryParam.factoryOrder" placeholder="请输入企业编码" />
        </div>
      </div>

      <div class="input-wrap">
        <div class="label">统一社会信用代码:</div>
        <div class="input-item">
          <j-input
            :maxLength="30"
            clearable
            v-model="queryParam.factoryCreditCode"
            placeholder="请输入统一社会信用代码"
          />
        </div>
      </div>

      <div class="input-wrap">
        <div class="label">退出时间:</div>
        <div class="time-item">
          <start-end-time
            :times="times"
            :showTime="{ format: 'HH:mm:ss' }"
            format="YYYY-MM-DD HH:mm:ss"
            @timeChange="timeChange"
            :resetTime="resetTime"
          ></start-end-time>
        </div>
      </div>

      <div class="btn-wrap">
        <a-button
          class="searchBtn"
          @click="searchQuery(queryParam.outTime_begin, queryParam.outTime_end)"
          type="primary"
        >
          搜索
        </a-button>
        <a-button class="resetBtn" @click="searchReset()" type="primary">重置</a-button>
      </div>
    </div>

    <div class="flex table-wrap">
      <a-table
        rowKey="id"
        class="tableList f1"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        @change="handleTableChange"
      >
        <template v-slot:factoryCode="records">
          <span class="operation">{{ records.factoryCode }}-{{ prefixZero(records.factoryOrder, 3) }}</span>
        </template>
        <template v-slot:action="records">
          <span class="operation deatil-color" @click="detailHandle(records)">详情</span>
          <span class="operation deatil-color" @click="showMNHandle(records)">MN码</span>
          <a-popconfirm title="确定要删除吗?" @confirm="() => exitManage(records.id)">
            <span class="operation del-color">删除</span>
          </a-popconfirm>
        </template>
      </a-table>
    </div>
  </div>
</template>
<script>
import startEndTime from '@/components/startEndTime'
import { factoryDelete } from '@/api/factory'
import { prefixZero } from '@/utils/util'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'

export default {
  name: 'visitor-toVisit',
  components: { startEndTime },
  mixins: [JeecgListMixin],
  data() {
    return {
      url: {
        list: '/factory/page?status=2',
      },
      columns: [
        {
          title: '序号',
          align: 'center',
          width: 100,
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '企业名称',
          dataIndex: 'factoryName',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '统一社区信用代码',
          dataIndex: 'factoryCreditCode',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '企业编码',
          // dataIndex: 'factoryCode',
          ellipsis: true,
          align: 'center',
          scopedSlots: { customRender: 'factoryCode' },
        },
        {
          title: '设备名称',
          dataIndex: 'factoryDeviceName',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '备案联系人',
          dataIndex: 'factoryUserName',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '联系电话',
          dataIndex: 'factoryMobile',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '退出时间',
          dataIndex: 'outTime',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '操作',
          width: 260,
          align: 'center',
          scopedSlots: { customRender: 'action' },
        },
      ],
    }
  },
  mounted() {},
  methods: {
    prefixZero,
    timeChange(v, index) {
      if (index == 1) {
        this.queryParam.outTime_begin = this.$moment(v).valueOf()
      } else {
        this.queryParam.outTime_end = this.$moment(v).valueOf()
      }
      if (v == null) {
        this.queryParam.outTime_begin = null
        this.queryParam.outTime_end = null
      }
    },

    detailHandle(records) {
      let data = {
        btnFlag: 0,
        ...records,
        content: '退出备案企业详情',
      }
      this.$router.push({ path: '/filingManagement/detail', query: data })
    },

    showMNHandle(records) {
      let data = {
        mnFlag: 0,
        ...records,
      }
      this.$router.push({ path: '/filingManagement/mn', query: data })
    },

    async exitManage(id) {
      let res = await factoryDelete({ id })
      this.$message.success(res.message)
      this.searchQuery()
    },
  },
}
</script>

<style lang="less" scoped></style>
